<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>interp</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="integ.html" title="integ" />
    <link rel="next" href="invalue.html" title="invalue" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">interp</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="integ.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="invalue.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="interp"></a>
      <div class="titlepage"></div>
      <a id="IndexInterp" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">interp</span>
        </h2>
        <p>interp — 
      Converts a control signal to an audio signal using linear interpolation.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp117132352"></a>
        <h2>Description</h2>
        <p>
      Converts a control signal to an audio signal using linear interpolation.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp117133760"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>interp</strong></span> ksig [, iskip] [, imode]</pre>
      </div>
      <div class="refsect1">
        <a id="idp117136016"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iskip</em></span> (optional, default=0) -- initial disposition of internal save space (see <a class="link" href="reson.html" title="reson"><em class="citetitle">reson</em></a>). The default value is 0.
    </p>
        <p>
      <span class="emphasis"><em>imode</em></span> (optional, default=0) -- sets the initial output value to the first k-rate input instead of zero.  The following graphs show the output of interp with a constant input value, in the original, when skipping init, and in the new mode:

      </p>
        <div class="example">
          <a id="idp117139792"></a>
          <p class="title">
            <strong>Example 404. iskip=0, imode=0</strong>
          </p>
          <div class="example-contents">
            <div class="literallayout">
              <p><br />
 |    ________<br />
 |   /        <br />
 |  /         <br />
 | /          <br />
 |/           <br />
-+------------<br />
 |            <br />
        </p>
            </div>
          </div>
        </div>
        <p><br class="example-break" />

      </p>
        <div class="example">
          <a id="idp117141728"></a>
          <p class="title">
            <strong>Example 405. iskip=1, imode=0</strong>
          </p>
          <div class="example-contents">
            <div class="literallayout">
              <p><br />
(prev)<br />
 |  __________<br />
 | /          <br />
 |/           <br />
 |            <br />
 |            <br />
-+------------<br />
 |            <br />
        </p>
            </div>
          </div>
        </div>
        <p><br class="example-break" />

      </p>
        <div class="example">
          <a id="idp117143632"></a>
          <p class="title">
            <strong>Example 406. iskip=0, imode=1</strong>
          </p>
          <div class="example-contents">
            <div class="literallayout">
              <p><br />
 |____________<br />
 |<br />
 |<br />
 |<br />
 |<br />
-+------------<br />
 |<br />
        </p>
            </div>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp117145776"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ksig</em></span> -- input k-rate signal.
    </p>
        <p>
      <span class="emphasis"><em>interp</em></span> converts a control signal to an audio signal. It uses linear interpolation between successive kvals. 
    </p>
      </div>
      <div class="refsect1">
        <a id="idp117148544"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the interp opcode. It uses the file <a class="ulink" href="examples/interp.csd" target="_top"><em class="citetitle">interp.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp117150320"></a>
          <p class="title">
            <strong>Example 407. Example of the interp opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o interp.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">; Initialize the global variables.</span>
<span class="ohdr">sr</span> <span class="op">=</span> 8000
<span class="ohdr">kr</span> <span class="op">=</span> 8
<span class="ohdr">ksmps</span> <span class="op">=</span> 1000
<span class="ohdr">nchnls</span> <span class="op">=</span> 1

<span class="comment">; Instrument #1 - a simple instrument.</span>
<span class="oblock">instr</span> 1
  <span class="comment">; Create an amplitude envelope.</span>
  kamp <span class="opc">linseg</span> 0, p3<span class="op">/</span>2, 20000, p3<span class="op">/</span>2, 0

  <span class="comment">; The amplitude envelope will sound rough because it</span>
  <span class="comment">; jumps every ksmps period, 1000.</span>
  a1 <span class="opc">oscil</span> kamp, 440, 1
  <span class="opc">out</span> a1
<span class="oblock">endin</span>

<span class="comment">; Instrument #2 - a smoother sounding instrument.</span>
<span class="oblock">instr</span> 2
  <span class="comment">; Create an amplitude envelope.</span>
  kamp <span class="opc">linseg</span> 0, p3<span class="op">/</span>2, 25000, p3<span class="op">/</span>2, 0
  aamp <span class="opc">interp</span> kamp

  <span class="comment">; The amplitude envelope will sound smoother due to</span>
  <span class="comment">; linear interpolation at the higher a-rate, 8000.</span>
  a1 <span class="opc">oscil</span> aamp, 440, 1
  <span class="opc">out</span> a1
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="comment">; Table #1, a sine wave.</span>
<span class="stamnt">f</span> 1 0 256 10 1

<span class="comment">; Play Instrument #1 for two seconds.</span>
<span class="stamnt">i</span> 1 0 2
<span class="comment">; Play Instrument #2 for two seconds.</span>
<span class="stamnt">i</span> 2 2 2
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp117154608"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="diff.html" title="diff"><em class="citetitle">diff</em></a>,
      <a class="link" href="downsamp.html" title="downsamp"><em class="citetitle">downsamp</em></a>,
      <a class="link" href="integ.html" title="integ"><em class="citetitle">integ</em></a>,
      <a class="link" href="samphold.html" title="samphold"><em class="citetitle">samphold</em></a>,
      <a class="link" href="upsamp.html" title="upsamp"><em class="citetitle">upsamp</em></a>
    </p>
        <p> More information on this opcode: <a class="ulink" href="http://www.csoundjournal.com/issue10/CsoundRates.html" target="_top"><em class="citetitle">http://www.csoundjournal.com/issue10/CsoundRates.html</em></a>  , written by Andrés Cabrera </p>
      </div>
      <div class="refsect1">
        <a id="idp117161952"></a>
        <h2>Credits</h2>
        <p>Updated November 2002, thanks to a note from both Rasmus Ekman and Istvan Varga.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="integ.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="invalue.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">integ </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> invalue</td>
        </tr>
      </table>
    </div>
  </body>
</html>
